package dao.Impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import dao.IRoomDao;
import db.DbConnection;

import po.Room;

public class RoomDaoImpl implements IRoomDao {
	private Connection conn = null;

	@Override
	public Room get(int roomNo) {
		Room room = new Room();
		conn = DbConnection.getConnection();
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			String sql = "SELECT * FROM room WHERE room_no =?";
			ps= conn.prepareStatement(sql);
			ps.setInt(1, roomNo);
			rs = ps.executeQuery();
			while(rs.next()) {
				room.setRoomNo(rs.getInt(1));
				room.setRoomName(rs.getString(2));
			}
		}catch(Exception e) {
			e.printStackTrace();
		}
		return room;
		
	}
	@Override
	public Room get(String roomName) {
		Room room = new Room();
		conn = DbConnection.getConnection();
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			String sql = "SELECT * FROM room WHERE room_name =?";
			ps= conn.prepareStatement(sql);
			ps.setString(1, roomName);
			rs = ps.executeQuery();
			while(rs.next()) {
				room.setRoomNo(rs.getInt(1));
				room.setRoomName(rs.getString(2));
			}
		}catch(Exception e) {
			e.printStackTrace();
		}
		return room;
		
	}

}
